package cn.dceast.api.resource;

import cn.dceast.common.result.RtnData;
import cn.dceast.service.ElectricService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by root on 16-11-21.
 */
@Controller
@RequestMapping("/electricApi")
public class ElectricPowerResource {

    Logger log = Logger.getLogger(ElectricPowerResource.class);

    @Autowired
    private ElectricService electricService;

    /**
     * 获取电费账单
     * @param paramMap
     * @return
     */
    @RequestMapping("/getElectricBill")
    @ResponseBody
    public RtnData getElectricBill(@RequestBody Map<String, Object> paramMap){
        log.error("请求参数-->"+paramMap);
        if(paramMap == null || paramMap.isEmpty()){
            return RtnData.fail(null, "请求参数为空。");
        }
        List list = electricService.getElectricBill(paramMap);
        if(list == null){
            return RtnData.fail(null, "请求数据失败。");
        }
        else {
            return RtnData.ok(list, "请求数据成功。");
        }
    }

    /**
     * 查询实时欠费信息
     * @param paramMap
     * @return
     */
    @RequestMapping("/getElectricArrearsInfo")
    @ResponseBody
    public RtnData getElectricArrearsInfo(@RequestBody Map<String, Object> paramMap){
        log.error("请求参数-->"+paramMap);
        if(paramMap == null || paramMap.isEmpty()){
            return RtnData.fail(null, "请求参数为空。");
        }
        Map map = electricService.getElectricArrearsInfo(paramMap);
        if(map == null){
            return RtnData.fail(null, "请求数据失败。");
        }
        else {
            return RtnData.ok(map, "请求数据成功。");
        }
    }

    /**
     * 查询实时余额信息
     * @param paramMap
     * @return
     */
    @RequestMapping("/getElectricBalanceInfo")
    @ResponseBody
    public RtnData getElectricBalanceInfo(@RequestBody Map<String, Object> paramMap){
        log.error("请求参数-->"+paramMap);
        if(paramMap == null || paramMap.isEmpty()){
            return RtnData.fail(null, "请求参数为空。");
        }
        Map map = electricService.getElectricBalanceInfo(paramMap);
        if(map == null){
            return RtnData.fail(null, "请求数据失败。");
        }
        else {
            return RtnData.ok(map, "请求数据成功。");
        }
    }

    /**
     * 查询缴费记录信息
     * @param paramMap
     * @return
     */
    @RequestMapping("/getPayRecordsInfo")
    @ResponseBody
    public RtnData getPayRecordsInfo(@RequestBody Map<String, Object> paramMap){
        log.error("请求参数-->"+paramMap);
        if(paramMap == null || paramMap.isEmpty()){
            return RtnData.fail(null, "请求参数为空。");
        }
        List list = electricService.getPayRecordsInfo(paramMap);
        if(list == null){
            return RtnData.fail(null, "请求数据失败。");
        }
        else {
            return RtnData.ok(list, "请求数据成功。");
        }
    }

    /**
     * 查询用电趋势
     * @param paramMap
     * @return
     */
    @RequestMapping("/getElectricTrend")
    @ResponseBody
    public RtnData getElectricTrend(@RequestBody Map<String, Object> paramMap){
        log.error("请求参数-->"+paramMap);
        if(paramMap == null || paramMap.isEmpty()){
            return RtnData.fail(null, "请求参数为空。");
        }
        List list = electricService.getElectricTrend(paramMap);
        if(list == null){
            return RtnData.fail(null, "请求数据失败。");
        }
        else {
            return RtnData.ok(list, "请求数据成功。");
        }
    }
}
